package com.andengine.editor.textureregioneditor;

import javax.swing.JFormattedTextField;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.text.NumberFormatter;

/**
 * @author sad
 */
public class NumberSpinner extends JSpinner {

    public NumberSpinner() {
        super(new SpinnerNumberModel(1, 1, 99999, 1));
        JFormattedTextField txt = ((JSpinner.NumberEditor) getEditor()).getTextField();
        ((NumberFormatter) txt.getFormatter()).setAllowsInvalid(false);
    }

    public void setStepSize(int step) {
        ((SpinnerNumberModel) getModel()).setStepSize(step);
    }

    public void setMin(int min) {
        ((SpinnerNumberModel) getModel()).setMinimum(min);
    }

    public void setMax(int max) {
        ((SpinnerNumberModel) getModel()).setMaximum(max);
    }

    public void setCurrent(int value) {
        ((SpinnerNumberModel) getModel()).setValue(value);
    }

}
